﻿using System;

class Person
{
    private string firstName;
    private string lastName;
    private int age;
    private DateTime birthDate;

    //public event PropertyChangedEventHandler FirstNameChanged;
    //public event PropertyChangedEventHandler LastNameChanged;
    //public event PropertyChangedEventHandler AgeChanged;
    //public event PropertyChangedEventHandler BirthDateChanged;
    public event PropertyChangedEventHandler PropertyChanged;

    
    public string FirsName
    {
        get { return firstName; }
        set 
        {             
            //OnFirstNameChanged(this.firsName,value);
            OnPropertyChange("First name", this.firstName, value);
            firstName = value;
        }
    }

    public string LastName
    {
        get { return lastName; }
        set 
        {
            //OnLastNameChanged(this.lastName,value);
            OnPropertyChange("Last name", this.lastName, value);
            lastName = value;            
        }
    }

    public int Age
    {
        get { return age; }
        set 
        {
            //OnAgeChanged(this.age,value);
            OnPropertyChange("Age", this.age, value);
            age = value;            
        }
    }
    
    public DateTime BirthDate
    {
        get { return birthDate; }
        set 
        {
            //OnBirthDateChanged(this.birthDate,value);
            OnPropertyChange("Birth date", this.birthDate, value);
            birthDate = value;            
        }
    }

    public Person(string firstName, string lastName, byte age, DateTime birthDate)
    {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
        this.birthDate = birthDate;
    }

    //protected void OnFirstNameChanged(string oldName,string newName)
    //{
    //    if (FirstNameChanged != null)
    //    {
    //        PropertyChangedEventArgs args = new PropertyChangedEventArgs("First name", oldName, newName);
    //        FirstNameChanged(this, args);
    //    }
    //}

    //protected void OnLastNameChanged(string oldName, string newName)
    //{
    //    if (LastNameChanged != null)
    //    {
    //        PropertyChangedEventArgs args = new PropertyChangedEventArgs("Last name", oldName, newName);
    //        LastNameChanged(this, args);
    //    }
    //}

    //protected void OnAgeChanged(int oldАgе, int newAge)
    //{
    //    if (AgeChanged != null)
    //    {
    //        PropertyChangedEventArgs args = new PropertyChangedEventArgs("Age", oldАgе, newAge);
    //        AgeChanged(this, args);
    //    }
    //}

    //protected void OnBirthDateChanged(DateTime oldDate, DateTime newDate)
    //{
    //    if (BirthDateChanged != null)
    //    {
    //        PropertyChangedEventArgs args = new PropertyChangedEventArgs("Birth date", oldDate, newDate);
    //        BirthDateChanged(this, args);
    //    }
    //}

    protected void OnPropertyChange(string properyName, object oldValue, object newValue)
    {
        if (PropertyChanged != null)
        {
            PropertyChangedEventArgs args = new PropertyChangedEventArgs(properyName, oldValue, newValue);
            PropertyChanged(this, args);
        }
    }
}
